package com.millstein.tsinglog.service.impl;

import com.millstein.tsinglog.commons.constant.SystemConstant;
import com.millstein.tsinglog.commons.enums.ResultCode;
import com.millstein.tsinglog.exception.TsinglogException;
import com.millstein.tsinglog.commons.service.BaseService;
import com.millstein.tsinglog.mapper.biz.LogMapper;
import com.millstein.tsinglog.model.pojo.Log;
import com.millstein.tsinglog.service.LogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class LogServiceImpl extends BaseService implements LogService {

    @Autowired
    private LogMapper logMapper;

    @Override
    public void insertLog(Log log) {

        log.setStatus(SystemConstant.STATUS_ENTITY_NORMAL);
        log.setCreateTime(getCurrentDateStr());
        log.setUpdateTime(getCurrentDateStr());

        int result = logMapper.insert(log);
        if (result != 1) {
            throw new TsinglogException(ResultCode.LOG_SAVE_FAILURE);
        }
    }
}
